package org.gpf.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
/**
 * 
* @ClassName: DBUtil 
* @Description: 数据库连接
* @author gaopengfei
* @date 2015-9-29 下午2:05:41 
 */
public class DBUtil {
	
    private static final String DB_DRIVER = "org.gjt.mm.mysql.Driver";
    private static final String DB_URL = "jdbc:mysql://127.0.0.1:3306/36Kr?characterEncoding=utf-8";
    private static final String DB_USER = "root";
    private static final String DB_PASSWORD = "mysqladmin";
    
    private static Connection conn = null;
    
    static{
    	try {
			Class.forName(DB_DRIVER);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
    }
    
    public static final Connection getConnection() throws SQLException{
    	
    	conn = DriverManager.getConnection(DB_URL, DB_USER, DB_PASSWORD);
    	return conn;
    }
    
    public void close() throws SQLException{
    	
    	if(conn != null){
    		conn.close();
    		conn = null;
    	}
    }
}
